/*
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 */

/* $Id: netutils.h 38 2007-07-13 09:57:08Z kf701.ye $ */

#ifndef _NET_UTIL_LIB_H_
#define _NET_UTIL_LIB_H_

#include <stdint.h>
#include <stdbool.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include <netdb.h>

int connect_nonblock(char *ip,uint16_t port,uint32_t timeout); 
int open_listenfd(uint16_t port); 
int open_udp(uint16_t port); 

bool setup_route(char *gateway_ip);
bool delete_route(char *gateway_ip);
void display_route(void);

void setnonblocking(int fd);

/* unix socket */
int unix_socket_new(void);
void unix_socket_free(int sockfd);
int32_t unix_socket_send(int sockfd , const char *to_path, const char *data, uint32_t size);
int unix_socket_new_listen(const char *unix_path);

/* send email */
typedef struct{
	char *smtp;
	char *passwd;
	char *from;
	char **to;
	uint32_t  numto;
	char *context;
	char *subject;
#define EMAIL_CHARSET	"utf-8"
#define EMAIL_MAXLINE	128
#define EMAIL_MIME	"MIME-Version: 1.0"
#define EMAIL_BOUNDARY	"---kf701libofmailsend---"
} mail_t;
bool send_mail(mail_t *mail);

/* network server */
typedef void (*tcp_data_func)(int, uint8_t*, uint32_t);
void tcp_server_epoll( uint16_t port, uint32_t psize, tcp_data_func func);
void tcp_server_select( uint16_t port, uint32_t psize, tcp_data_func func);

typedef void (*tcp_fd_func)(int);
void tcp_server_select_2( uint16_t port, tcp_fd_func func);

typedef void(*udp_data_func)(struct sockaddr*, uint8_t*, uint32_t);
void udp_server(uint16_t port, uint32_t psize, udp_data_func func);

typedef void(*un_data_func)(const char*, uint8_t*, uint32_t);
void unix_socket_server( const char *unix_path, uint32_t psize, un_data_func func);


#endif
